from time import sleep
import os
from selenium import webdriver
from selenium.webdriver.common.by import By

# 表单综合实例
url = os.path.abspath("注册实例.html")
driver = webdriver.Chrome()
driver.get("url")
sleep(2)
driver.find_element(By.ID, "user").send_keys("1111")
driver.find_element(By.ID, "password").send_keys("1111")
driver.find_element(By.ID, "tel").send_keys("1111")
driver.find_element(By.ID, "email").send_keys("1111")
driver.find_element(By.TAG_NAME, "button").click()
sleep(2)
# 切入frame1标签
driver.switch_to.frame("myframe1")
driver.find_element(By.ID, "userA").send_keys("2222")
driver.find_element(By.ID, "passwordA").send_keys("2222")
driver.find_element(By.ID, "telA").send_keys("2222")
driver.find_element(By.ID, "emailA").send_keys("2222")
driver.find_element(By.TAG_NAME, "button").click()
sleep(2)
# 从frame1回到主页面
driver.switch_to.default_content()
# 切入frame2标签
driver.switch_to.frame("myframe2")
driver.find_element(By.ID, "userB").send_keys("3333")
driver.find_element(By.ID, "passwordB").send_keys("3333")
driver.find_element(By.ID, "telB").send_keys("3333")
driver.find_element(By.ID, "emailB").send_keys("3333")
driver.find_element(By.TAG_NAME, "button").click()
sleep(2)


# 登录163邮箱
driver = webdriver.Chrome()
driver.get("https://mail.163.com")
driver.maximize_window()
sleep(2)
# 查找iframe的name标签
name = driver.find_element(By.TAG_NAME, "iframe")
print(name.get_attribute("outerHTML"))
# 切入frame
driver.switch_to.frame("")
email = driver.find_element(By.NAME, "email")
email.send_keys("173123456")
pwd = driver.find_element(By.NAME, "password")
pwd.send_keys("12345678")
driver.find_element(By.ID, "dologin").click()
sleep(5)


